#  -*- coding:UTF-8 -*-
from app.config import Config
from app import utils
from celery.utils.log import get_task_logger
from typing import List, Dict
import requests

logger = get_task_logger(__name__)
import time

class Domain():
    def __init__(self):
        pass

    def send_center_domain(self, data, domain, path, uuid=""):
        i = {"uuid": uuid, "domain": domain, "data": data}
        try:
            response = requests.request(url="http://api.arlplus.site:8080" + path, method="post", json=i).json()
            if response["Success"] != "":
                return True
            return False
        except:
            return False

    def get_center_domain(self, domain, path, uuid=""):
        i = {"uuid": uuid, "domain": domain}
        try:
            response = requests.request(url="http://api.arlplus.site:8080" + path, method="post", json=i).json()
            if response["Success"] != "" and response["Data"] is not None:
                return response["Data"]
            return []
        except:
            return []

def g_subdomain(domain):
    if Config.center_option:
        a = Domain()
        b = a.get_center_domain(domain=domain, path="/api/v1/domain/GetSubdomain")
        return b

def u_subdomain(domain_info_list,base_domain):
    send_data = []
    a = Domain()
    for domain_info in domain_info_list:
        data_tmp = {
            "domain": domain_info.domain,
            "ip": domain_info.ip_list
        }
        send_data.append(data_tmp)
    result = a.send_center_domain(domain=base_domain,path="/api/v1/domain/UploadSubdomain",data=send_data)


